import pygal
from die import Die

# 创建一个6面骰子D6和一个10面骰子D10
die_1 = Die()
die_2 = Die(10)

# 掷几次骰子，并将结果存储在一个列表中
# 将两个骰子的点数相加
results = [(die_1.roll() + die_2.roll()) for roll_num in range(50000)]
#for roll_num in range(50000):
#    result = die_1.roll() + die_2.roll()
#    results.append(result)

# 分析结果
max_result = die_1.num_sides + die_2.num_sides
# 方法count计算每种点数在results中出现了多少次
frequencies = [(results.count(value)) for value in range(2, max_result + 1)]
# for value in range(2, max_result + 1):
#    frequency = results.count(value)
#    frequencies.append(frequency)

# 对结果进行可视化
hist = pygal.Bar()

hist.title = "Results of rolling a D6 and a D10 50000 times."
hist.x_labels = []
for x_label in range(2, max_result + 1):
    hist.x_labels.append(str(x_label))
hist.x_title = "Result"
hist.y_title = "Frequency of Result"

hist.add('D6 + D10', frequencies)
hist.render_to_file('dice_visual.svg')

print(frequencies)